namespace EyeSoft.Accounting.Italian
{
	public class ControlCode : Code
	{
		private readonly string lastNameCode;

		private readonly string firstNameCode;

		private readonly string yearCode;

		private readonly string monthCode;

		private readonly string dayCode;

		private readonly string areaCode;

		internal ControlCode(
			LastNameCode lastNameCode,
			FirstNameCode firstNameCode,
			YearCode yearCode,
			MonthCode monthCode,
			DayCode dayCode,
			AreaCode areaCode)
		{
			this.lastNameCode = lastNameCode.ToString();
			this.firstNameCode = firstNameCode.ToString();
			this.yearCode = yearCode.ToString();
			this.monthCode = monthCode.ToString();
			this.dayCode = dayCode.ToString();
			this.areaCode = areaCode.ToString();
		}

		protected internal override string GetCode()
		{
			var partialCode =
				string.Concat(lastNameCode, firstNameCode, yearCode, monthCode, dayCode, areaCode);

			var sum = 0;

			sum += new OddCode(partialCode).Total;
			sum += new EvenCode(partialCode).Total;

			var controlCode = new RestCode(sum).ToString();

			return controlCode;
		}
	}
}